package com.example.noval.network

import com.example.noval.network.api.BookService
import okhttp3.OkHttp
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import retrofit2.create
import java.util.concurrent.TimeUnit
import java.util.logging.LoggingPermission

/**
 * @Description
 * @Author zzl
 * @Date 2024/3/23
 */
object ServiceCreator {
    
    private const val BASE_URL="https://api.midukanshu.com/"
    private const val BASE_URL1="https://book.midukanshu.com/"
    
    val logging = HttpLoggingInterceptor().apply {
        level = HttpLoggingInterceptor.Level.BODY
    }

    private val httpClient=OkHttpClient.Builder()
        .connectTimeout(15,TimeUnit.SECONDS)
        .writeTimeout(15,TimeUnit.SECONDS)
        .readTimeout(15,TimeUnit.SECONDS)
        .addInterceptor(logging)
        
    //搜索api
    private val builder=Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(httpClient.build())
        .addConverterFactory(ScalarsConverterFactory.create())
        .addConverterFactory(GsonConverterFactory.create())

    //book api
    private val builder1=Retrofit.Builder()
        .baseUrl(BASE_URL1)
        .client(httpClient.build())
        .addConverterFactory(ScalarsConverterFactory.create())
        .addConverterFactory(GsonConverterFactory.create())

    private val retrofit= builder.build()
    private val retrofit1= builder1.build()
    
    fun <T> create(serviceClass:Class<T>):T= retrofit.create(serviceClass)
    fun <T> create1(serviceClass:Class<T>):T= retrofit1.create(serviceClass)

    val apiService: BookService = retrofit.create(BookService::class.java)
    val apiService1: BookService = retrofit1.create(BookService::class.java)




}